﻿using System;
using Newtonsoft.Json;

namespace BackTask.Model
{
    public class SimpleTaskJob : TaskJob
    {
        [JsonProperty("config")]
        public SimpleTaskExecuteConfig ExcuteConfig { get; }
        
        public SimpleTaskJob(string url) : this(DateTime.Now.ToString(), url, SimpleTaskExecuteConfig.DefaultConfig, 0, string.Empty, Constants.DEFAULT_GROUP_NAME) { }

        public SimpleTaskJob(string url, string name) : this(url, name, SimpleTaskExecuteConfig.DefaultConfig, 0, string.Empty, Constants.DEFAULT_GROUP_NAME) { }

        public SimpleTaskJob(string url, string name, SimpleTaskExecuteConfig executeConfig) : this(url, name, executeConfig, 0, string.Empty, Constants.DEFAULT_GROUP_NAME) { }

        public SimpleTaskJob(string url, string name, SimpleTaskExecuteConfig executeConfig, int priority) : this(url, name, executeConfig, priority, string.Empty, Constants.DEFAULT_GROUP_NAME) { }

        public SimpleTaskJob(string url, string name, SimpleTaskExecuteConfig executeConfig, int priority, string description) : this(url, name, executeConfig, priority, description, Constants.DEFAULT_GROUP_NAME) { }

        public SimpleTaskJob(string url, string name, SimpleTaskExecuteConfig executeConfig, int priority, string description, string groupName)
        {
            this.Name = name;
            this.ExcuteConfig = executeConfig;
            this.Url = url;
            this.Priority = priority;
            this.Description = description;
            this.GroupName = groupName;
        }
    }
    
    public class SimpleTaskExecuteConfig
    {
        [JsonProperty("interval")]
        public int Interval { get; set; }

        [JsonProperty("executeCount")]
        public int ExecuteCount { get; set; }

        [JsonProperty("intervalType")]
        public SimpleTaskJobIntervalTypes IntervalType { get; set; }

        [JsonProperty("repeatForever")]
        public bool RepeatForever { get; set; }

        public readonly static SimpleTaskExecuteConfig DefaultConfig = new SimpleTaskExecuteConfig()
        {
            ExecuteCount = 1,
            RepeatForever = false,
            IntervalType = SimpleTaskJobIntervalTypes.Second,
            Interval = 1,
        };
    }
}
